package edu.nf.exam.dao.impl;

import edu.nf.exam.dao.PaperQuestionInfoDao;
import edu.nf.exam.entity.PaperQuestionInfo;
import edu.nf.exam.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Author : QYM
 * @create 2021/6/17
 * 试题信息表--接口实现类
 */
public class PaperQuestionInfoDaoImpl implements PaperQuestionInfoDao {
    /**
     * 查询
     * @param paperQuestionInfo
     * @return
     */
    @Override
    public List<PaperQuestionInfo> select(PaperQuestionInfo paperQuestionInfo) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<PaperQuestionInfo> list = sqlSession.getMapper(PaperQuestionInfoDao.class).select(paperQuestionInfo);
        sqlSession.close();
        return list;
    }


    /**
     * 根据ID查询
     * @param paperQuestionId
     * @return
     */
    @Override
    public PaperQuestionInfo selectById(Integer paperQuestionId) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        PaperQuestionInfo paperQuestionInfo = sqlSession.getMapper(PaperQuestionInfoDao.class).selectById(paperQuestionId);
        sqlSession.close();
        return paperQuestionInfo;
    }

    /**
     * 添加
     * @param paperQuestionInfo
     * @return
     */
    @Override
    public int add(PaperQuestionInfo paperQuestionInfo) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        int r = sqlSession.getMapper(PaperQuestionInfoDao.class).add(paperQuestionInfo);
        sqlSession.close();
        return r;
    }

    /**
     * 修改
     * @param paperQuestionInfo
     * @return
     */
    @Override
    public int update(PaperQuestionInfo paperQuestionInfo) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        int r = sqlSession.getMapper(PaperQuestionInfoDao.class).update(paperQuestionInfo);
        sqlSession.close();
        return r;
    }

    /**
     * 分页查询
     * @param paperQuestionId
     * @param difficult
     * @param questionType
     * @param levelName
     * @param subjectName
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public List<PaperQuestionInfo> selectByPage(Integer paperQuestionId,Integer difficult, Integer questionType, String levelName, String subjectName,Integer pageNum,Integer pageSize) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<PaperQuestionInfo> list = sqlSession.getMapper(PaperQuestionInfoDao.class).selectByPage(paperQuestionId,difficult, questionType, levelName, subjectName,pageNum,pageSize);
        sqlSession.close();
        return list;
    }

    /**
     * 查询题目月数量
     * @param createTime
     * @return
     */
    @Override
    public List<PaperQuestionInfo> selectMonthCount(String createTime) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession(true);
        List<PaperQuestionInfo> list = sqlSession.getMapper(PaperQuestionInfoDao.class).selectMonthCount(createTime);
        sqlSession.close();
        return list;
    }
}
